<template>
  <base-breadcrumb>
    <a-card>
      <title-name title="信息详情" />
      <a-form>
        <a-row :gutter="24" type="flex">
          <a-col :md="8" :sm="8">
            <a-form-item
              label="名称"
              :labelCol="{ lg: { span: 5 }, sm: { span: 5 } }"
              :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
            >
              {{ formInfo.projectTitle }}
            </a-form-item>
          </a-col>
          <a-col :md="16" :sm="16">
            <a-form-item
              label="所属单位"
              :labelCol="{ lg: { span: 5 }, sm: { span: 5 } }"
              :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
            >
              {{ formInfo.branchComName + "/" + formInfo.projectName }}
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-item
              label="本次优化率"
              :labelCol="{ lg: { span: 5 }, sm: { span: 5 } }"
              :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
            >
              {{ formInfo.rate }}
            </a-form-item>
          </a-col>
<!--          <a-col :md="8" :sm="8">-->
<!--            <a-form-item-->
<!--              label="所属分公司"-->
<!--              :labelCol="{ lg: { span: 5 }, sm: { span: 5 } }"-->
<!--              :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"-->
<!--            >-->
<!--              {{ formInfo.branchComName }}-->
<!--            </a-form-item>-->
<!--          </a-col>-->
          <a-col :md="8" :sm="6">
            <a-form-item
              label="填报人"
              :labelCol="{ lg: { span: 6 }, sm: { span: 4 } }"
              :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
            >
              {{ formInfo.vompletedBy }}
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-item
              label="总优化率"
              :labelCol="{ lg: { span: 5 }, sm: { span: 5 } }"
              :wrapperCol="{ lg: { span: 18 }, sm: { span: 17 } }"
            >
              {{ formInfo.totalRate }}
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-item
              label="公司排名"
              :labelCol="{ lg: { span: 5 }, sm: { span: 5 } }"
              :wrapperCol="{ lg: { span: 18 }, sm: { span: 17 } }"
            >
              {{ formInfo.totalRanking }}
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-item
              label="分公司排名"
              :labelCol="{ lg: { span: 5 }, sm: { span: 5 } }"
              :wrapperCol="{ lg: { span: 18 }, sm: { span: 17 } }"
            >
              {{ formInfo.branchRanking }}
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-item
              label="填报时间"
              :labelCol="{ lg: { span: 5 }, sm: { span: 5 } }"
              :wrapperCol="{ lg: { span: 18 }, sm: { span: 17 } }"
            >
              {{ formInfo.createTime }}
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-card>
    <a-card>
      <title-name title="优化清单" />
      <a-table
        :data-source="formInfo.optimizations"
        :columns="typeYear == '下半年' ? columnsSecond : columnsFirst"
        bordered
        :pagination="false"
        row-key="id"
      >
        <span slot="description" slot-scope="text">
          <ellipsis :length="8" tooltip>{{ text }}</ellipsis>
        </span>
        <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
      </a-table>
    </a-card>
    <a-card>
      <title-name title="相关附件" />
      <!-- <a-table
        :data-source="formInfo.reviewFileInfoVOList"
        :columns="columns2"
        bordered
        :pagination="false"
        row-key="id"
      >
        <span slot="description" slot-scope="text">
          <ellipsis :length="8" tooltip>{{ text }}</ellipsis>
        </span>
        <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
        <span slot="operation" slot-scope="text, record">
          <template>
            <a @click="detailed(record)">查看</a>
            <a-divider type="vertical" />
            <a @click="addEdit(record)">下载</a>
            <a-divider type="vertical" />
            <a @click="discard(record)">打印</a>
          </template>
        </span>
      </a-table> -->
      <upload-list
        :disabled="true"
        :uploadArrys.sync="formInfo.reviewFileInfoVOList"
        :isClose="false"
        multiple
      ></upload-list>
    </a-card>
    <div class="tool-btns page-btn-right-top">
      <BasePrintButton v-if="formInfo.auditStatus == 'PAST'" type="primary" :before-print-fn="print" />
      <a-button type="primary" class="ml12" @click="handleClose" v-if="checkVisibleInDetail">返回</a-button>
    </div>
  </base-breadcrumb>
</template>

<script>
import UploadList from '@/components/UploadList'
import { getSteelDetail, print } from '@/api/technologySteel'
import { checkVisibleInDetail } from '@/utils/util'
import BasePrintButton from '@/components/BasePrintButton' // 打印按钮
const columnsFirst = [
  {
    title: '序号',
    width: '100px',
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '钢筋技术优化名称',
    dataIndex: 'name'
  },
  {
    title: '钢筋技术优化量（t）',
    dataIndex: 'optimizationAmount'
  },
  {
    title: '上半年钢筋工程使用总量（t）',
    dataIndex: 'engineeringAmount'
  },
  {
    title: '钢筋技术优化效益（万元）',
    dataIndex: 'optimizationBenefit'
  },
  {
    title: '上半年钢筋工程总造价（万元）',
    dataIndex: 'engineeringPrice'
  },
  {
    title: '钢筋技术优化效益率（%）',
    dataIndex: 'optimizationRate'
  }
]
const columnsSecond = [
  {
    title: '序号',
    width: '100px',
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '钢筋技术优化名称',
    dataIndex: 'name'
  },
  {
    title: '钢筋技术优化量（t）',
    dataIndex: 'optimizationAmount'
  },
  {
    title: '下半年钢筋工程使用总量（t）',
    dataIndex: 'engineeringAmount'
  },
  {
    title: '钢筋技术优化效益（万元）',
    dataIndex: 'optimizationBenefit'
  },
  {
    title: '下半年钢筋工程总造价（万元）',
    dataIndex: 'engineeringPrice'
  },
  {
    title: '钢筋技术优化效益率（%）',
    dataIndex: 'optimizationRate'
  }
]
const columns2 = [
  {
    title: '序号',
    width: '80px',
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '附件名称',
    dataIndex: 'fileName'
  },
  {
    title: '操作',
    dataIndex: 'operation',
    width: '170px',
    scopedSlots: { customRender: 'operation' }
  }
]
export default {
  name: 'a' + Date.now(),
  components: {
    UploadList,
    BasePrintButton
  },
  data() {
    this.columnsFirst = columnsFirst
    this.columnsSecond = columnsSecond
    this.columns2 = columns2
    return {
      checkVisibleInDetail: checkVisibleInDetail(this),
      formInfo: {},
      typeYear: ''
    }
  },
  props: {
    isAudit: {
      // 是否作为审批详情
      type: Boolean,
      default: false
    }
  },

  created() {
    this.getSteelDetail()
  },
  methods: {
    print() {
      return print({ id: this.$route.query.id }).then(res => {
        console.log(res)
        return res.data.content
      })
    },
    handleClose() {
      if (this.isAudit) {
        window.close()
      } else {
        this.$multiTab.close(this.$route.fullpath)
      }
    },

    getSteelDetail() {
      const id = this.$route.query.id
      if (!id) return
      getSteelDetail(id).then(res => {
        if (res.code === 200 || res.data.code === 200) {
          this.formInfo = { ...res.data, reviewFileInfoVOList: res.data.reviewFileInfoVOList || [] }
          this.typeYear = this.formInfo.projectTitle.slice(5, 8)
          console.log(this.typeYear)
          if (this.formInfo.projectTitle.indexOf('上半年') != -1) {
            this.typeYear = '上半年'
          } else {
            this.typeYear = '下半年'
          }
        }
      })
    }
  }
}
</script>

<style></style>
